import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
import DateTime

qxname = DateTime.DateTime().qxname()  # 生成抢修单的名称
import Mongo

qxmongo = Mongo.Mongo("qx", qxname)


class Computer:
    def computer(self, qxname):
        Qx = myclient["qx"][qxname]
        QxCount = Qx.estimated_document_count()
        JSB = myclient["JSB"]["jsb"]
        resultAll = 0
        resultAllTB = 0
        # miaoshu = []
        for n in range(1, QxCount + 1):
            miaoshu = []
            print("第" + str(n) + "个项目")
            workloadList = Qx.find_one({"_id": n})["workload"]
            GD49 = Qx.find_one({"_id": n})["GD49"]
            workloadLen = len(workloadList)
            result = 0
            for nn in range(0, workloadLen):
                workloadOneID = workloadList[nn]["JSid"]

                workloadOneUnit = workloadList[nn]["unit"]
                findJSB = JSB.find_one({"_id": workloadOneID})

                JSBFind = findJSB["jiage"]
                """"↓↓↓↓↓↓该段获取jsb单项说明信息↓↓↓↓↓"""
                SM1 = findJSB["neirong"]
                SM2 = findJSB["guige"]
                SM3 = findJSB["shuoming"]
                SM = "【(" + str(workloadOneID) + ")" + SM1 + " " + SM2 + " " + SM3 + " x " + str(workloadOneUnit) + "】"
                miaoshu.append(SM)
                """"↑↑↑↑↑↑↑该段获取jsb单项说明信息↑↑↑↑↑↑"""
                JS = round(workloadOneUnit * JSBFind, 2)
                result += JS
                print(str(workloadOneUnit) + "*" + str(JSBFind) + "=" + str(JS))
            print("第" + str(n) + "项金额" + str(round(result, 2)))
            print(GD49)
            if result>=500:
                resultAll+=result
                resultAllTB+=result
            elif result<500:
                resultAll+=result
                resultAllTB+=500

            qxmongo.collsetAmotunt(n, result, GD49, miaoshu)
        print(round(resultAll,2))
        print(round(resultAllTB,2))
